package com.itheima.d7Arrays;

import java.util.Arrays;
import java.util.Comparator;

public class Student {
    private String name;
    private int age;
    private  double height;

    public Student() {
    }

    public Student(String name, int age, double height) {
        this.name = name;
        this.age = age;
        this.height = height;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", height=" + height +
                '}';
    }
}
class Test3{
    public static void main(String[] args) {
        Student[] students = new Student[2];
        Student s1 = new Student("pxf",28,179.0);
        Student s2 = new Student("rs",26,185.4);
        students[0] = s1;
        students[1] = s2;
        Arrays.sort(students, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                if (o1.getHeight() > o2.getHeight()){
                    return -1;
                }else if (o1.getHeight() < o2.getHeight()){
                    return  1;
                } else {
                    return 0;
                }
            }
        });
        System.out.println(Arrays.toString(students));
    }
}
